//
// Created by lenovo on 2021/11/27.
//
#include "stdio.h"
#include "process.h"

int factorsum(int number), printYinZi(int i), Max(int i);

void PrintPN(int m, int n);

int experiment1() {
    int m, n;
    scanf("%d%d", &m, &n);
    PrintPN(m, n);
    system("pause");
}

void PrintPN(int m, int n) {
    int flag;
    for (int i = m; i <= n; ++i) {
        if (factorsum(i) == i) {//是完数
            printYinZi(i);//打印该完数的因子
            flag = 1;
            printf("\n");
        }
    }
    if (flag != 1) {
        printf("No perfect number\n");
    }
}

int factorsum(int number) {
    int sum = 0;
    for (int i = 1; i < number; ++i) {
        if (number % i == 0) {
            sum += i;
        }
    }
    return sum;
}

int printYinZi(int i) {//输出因子
    printf("%d=", i);
    int max = Max(i);
    for (int j = 1; j < i; ++j) {
        if (i % j == 0) {
            if (j == max) {
                printf("%d", j);
            } else printf("%d+", j);
        }
    }
}

int Max(int i) {
    int max = 0;
    for (int j = 1; j < i; ++j) {
        if (i % j == 0) {
            if (j > max) {
                max = j;
            }
        }
    }
    return max;
}